﻿using System;
using System.Drawing;

namespace ShpViewer
{
    public class Line
    {
        public double[] box;
        public int numParts;
        public int numPoints;
        public int[] parts;
        public PointF[] points;

        public Line()
        {}

        public void Read(ExtendBinaryReader extendBinaryReader)
        {
            int recordNumber = extendBinaryReader.ReadInt32UsingBigEndian();
            int recordLength = extendBinaryReader.ReadInt32UsingBigEndian();
            int recordShapeType = extendBinaryReader.ReadInt32();
            this.box = new Double[4];
            this.box[0] = extendBinaryReader.ReadDouble();
            this.box[1] = extendBinaryReader.ReadDouble();
            this.box[2] = extendBinaryReader.ReadDouble();
            this.box[3] = extendBinaryReader.ReadDouble();
            this.numParts = extendBinaryReader.ReadInt32();
            this.numPoints = extendBinaryReader.ReadInt32();
            this.parts = new int[this.numParts];
            for (int i = 0; i < this.numParts; i++)
            {
                this.parts[i] = extendBinaryReader.ReadInt32();
            }
            this.points = new PointF[this.numPoints];
            for (int i = 0; i < this.numPoints; i++)
            {
                this.points[i].X = (float)extendBinaryReader.ReadDouble();
                this.points[i].Y = (float)extendBinaryReader.ReadDouble();
                this.points[i].Y = 0 - this.points[i].Y;
            }
        }

        public void Render(Graphics g, double xMin, double yMax, float scaleX, float scaleY)
        {
            int n = this.points.Length;
            PointF[] pt = new PointF[n];
            for (int j = 0; j < n; j++)
            {
                pt[j].X = (this.points[j].X - (float)xMin) * scaleX;
                pt[j].Y = (this.points[j].Y - (float)yMax) * scaleY;
            }
            g.DrawLines(Pens.Black, pt);
        }
    }
}
